﻿@page "/communication-test"
@using BootstrapBlazor.Components

<h3>CommunicationTest</h3>


<GroupBox Title="串口设置">
    <div class="row form-inline g-3">
        <div class="col-12 col-sm-6">
            <Select Items="_baudRateList" @bind-Value="@_serialOptions.BaudRate" ShowLabel="true" DisplayText="波特率" />
        </div>
        <div class="col-12 col-sm-6">
            <Select Items="_dataBits" @bind-Value="@_serialOptions.DataBits" ShowLabel="true" DisplayText="数据位" />
        </div>
        <div class="col-12 col-sm-6">
            <Select Items="_stopBits" @bind-Value="@_serialOptions.StopBits" ShowLabel="true" DisplayText="停止位" />
        </div>
        <div class="col-12 col-sm-6">
            <Select @bind-Value="@_serialOptions.ParityType" ShowLabel="true" DisplayText="校验位" />
        </div>
        <div class="col-12 col-sm-6">
            <Select Items="_bufferSizes" @bind-Value="@_serialOptions.BufferSize" ShowLabel="true" DisplayText="缓冲区" />
        </div>
        <div class="col-12 col-sm-6">
            <Select @bind-Value="@_serialOptions.FlowControlType" ShowLabel="true" DisplayText="流控制" />
        </div>
        <div class="col-12">
            <Button OnClick="GetPort" Text="选择"></Button>
            <Button IsDisabled="CheckOpen" OnClick="OpenPort" Text="打开" class="ms-2"></Button>
            <Button IsDisabled="CheckClose" OnClick="ClosePort" Text="关闭" class="ms-2"></Button>
        </div>
        <div class="col-12">
            <Console Items="@_messages" Height="126" IsAutoScroll="true" HeaderText="接收数据" />
        </div>
        <div class="col-12">
            <div>发送数据</div>
        </div>
        <div class="col-12">
            <Textarea IsDisabled="CheckClose" @bind-Value="@_sendData" rows="3"></Textarea>
        </div>
        <div class="col-12 col-sm-6">
            <Checkbox @bind-Value="_appendCRLF" ShowAfterLabel="true" DisplayText="末尾加回车换行"></Checkbox>
            <Checkbox @bind-Value="_isHEX" ShowAfterLabel="true" DisplayText="HEX 发送" class="ms-3"></Checkbox>
        </div>
        <div class="col-12 col-sm-6">
            <Checkbox @bind-Value="_isLoop" ShowAfterLabel="true" DisplayText="循环发送" class="me-3"></Checkbox>
            <BootstrapInputGroup>
                <BootstrapInputGroupLabel DisplayText="发送间隔(ms)"></BootstrapInputGroupLabel>
                <BootstrapInput @bind-Value="_sendInterval"></BootstrapInput>
            </BootstrapInputGroup>
        </div>
        <div class="col-12">
            <Button IsDisabled="CheckClose" OnClick="Write" Text="发送"></Button>
        </div>
        <div class="col-12 col-sm-6">
            <Checkbox Value="_ring" ShowAfterLabel="true" DisplayText="RING"></Checkbox>
            <Checkbox Value="_dsr" ShowAfterLabel="true" DisplayText="DSR" class="ms-3"></Checkbox>
        </div>
        <div class="col-12 col-sm-6">
            <Checkbox Value="_cts" ShowAfterLabel="true" DisplayText="CTS"></Checkbox>
            <Checkbox Value="_dcd" ShowAfterLabel="true" DisplayText="DCD" class="ms-3"></Checkbox>
        </div>
        <div class="col-12">
            <Button IsDisabled="CheckClose" OnClick="GetSignals" Text="串口参数"></Button>
        </div>
        <div class="col-12 col-sm-6">
            <Display Value="@_usbInfo?.UsbVendorId" ShowLabel="true" DisplayText="VendorId"></Display>
        </div>
        <div class="col-12 col-sm-6">
            <Display Value="@_usbInfo?.UsbProductId" ShowLabel="true" DisplayText="ProductId"></Display>
        </div>
        <div class="col-12">
            <Button IsDisabled="CheckClose" OnClick="GetInfo" Text="USB 信息"></Button>
        </div>
    </div>
</GroupBox>
